package com.qizhou.base.dialog.lifecycledialog

import androidx.annotation.StyleRes
import android.view.ViewGroup
import android.view.Window

fun <T> List<T>.notifyOutLifecycleObservers(notifyItem: (observer: T) -> Unit) {
    for (outLifecycleObserver in this) {
        notifyItem(outLifecycleObserver)
    }
}
fun <T> MutableList<T>.removeIfIn(outLifecycleObserver: T) {
    if (outLifecycleObserver in this) {
        this.remove(outLifecycleObserver)
    }
}

fun <T> MutableList<T>.addIfAbsent(outLifecycleObserver: T) {
    if (outLifecycleObserver in this) {
        return
    }
    this.add(outLifecycleObserver)
}
fun Window.applyGravityStyle(gravity: Int, @StyleRes resId: Int?, width: Int =  ViewGroup.LayoutParams.MATCH_PARENT,
                             height: Int =  ViewGroup.LayoutParams.WRAP_CONTENT, x: Int = 0, y: Int = 0) {
    val attributes = this.attributes
    attributes.gravity = gravity
    attributes.width =  width
    attributes.height = height
    attributes.x = x
    attributes.y = y
    this.attributes = attributes
    resId?.let { this.setWindowAnimations(it) }
}